home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2008 May / PersonalComputerWorld-May2008-CoverdiscCD.iso / Software / Full / Nero 7 / Installation / Cab / 83AF5E4E.cab / MoveFocus881F83D2.js < prev    next >
Encoding:
JavaScript  |  2006-06-20  |  23.5 KB  |  616 lines

  1. // Variable to track where the focus is at any time. Its value will always be a focusable object on the page
  2. var oCurFocus
  3.  
  4. // variable to track where the focus was previous to current focus.
  5. var oPrevFocus = null
  6.  
  7. // variable to track which direction arrow was used to get between previous focus and current focus
  8. var sPrevArrowDirection = null
  9.  
  10. // variable to trap first mouseover event
  11. var bFirstMouseover = true
  12.  
  13. function startFocus()
  14. // this function sets the initial focus on the page, plus it takes care of a few other tasks that are linked to the onload event
  15. {
  16.     // make sure that scrollbar does not appear at the side of the page
  17.     // This is not integral to the rest of the function, but it's a convenient place to do it
  18.      body.scroll="no"
  19.  
  20.     //Reset the variable that traps the first mouseover event on the page
  21.     // This is not integral to the rest of the function, but it's a convenient place to do it
  22.     // The MouseOver function in the Hilite.js file checks this variable to handle mouseover events
  23.     // For more info, see comments in that file
  24.     window.setTimeout("bFirstMouseover = false", 100)
  25.  
  26.     // check if media is playing and Shared viewport needs to be opened
  27.     try
  28.     {
  29.         // call needViewport function, which checks if media is playing
  30.         if (needViewport() == true)
  31.         {
  32.             window.external.MediaCenter.SharedViewPort.Visible = true
  33.         }
  34.     }
  35.     catch(e)
  36.     {
  37.         // ignore error
  38.     }
  39.  
  40.     /* if you are arriving at the page via the Back button, then focus should start on the same
  41.     element it was on when you left. The browser will automatically focus on the correct element,
  42.     but for the element to highlight correctly, you have to update a variable, move the focus to
  43.     the BODY element, and then continue with the rest of this function. */
  44.     // Check to see if initial focus is already on a focusable element
  45.     if (document.activeElement.MCFocusable == "true")
  46.     {
  47.         // reset MCFocusStart variable, which instructs the page where to start the focus
  48.         body.MCFocusStart = document.activeElement
  49.         // move focus temporarily to BODY element, or focusable item will not highlight correctly
  50.         body.focus()
  51.     }
  52.  
  53.     // if oCurFocus does not already have a value, check the value for body.MCFocusStart
  54.     if (oCurFocus == null)
  55.     {
  56.         try
  57.         {
  58.             oCurFocus = eval(body.MCFocusStart)
  59.         }
  60.         catch(e)
  61.         {
  62.             // if MCFocusStart is invalid, ignore error
  63.         }
  64.     }
  65.  
  66.     // if body.MCFocusStart has no value, and oCurFocus still has no value,
  67.     // set oCurFocus to the first focusable item on the page. This will be the default state
  68.     if (oCurFocus == null)
  69.     {
  70.         try
  71.         {
  72.             oCurFocus = aFocusableItemsArray[0]
  73.             // make sure starting focus is not Shared Viewport
  74.             if (oCurFocus.id == "SVP")
  75.             {
  76.                 oCurFocus = aFocusableItemsArray[1]
  77.             }
  78.         }
  79.         catch(e)
  80.         {
  81.             //ignore error
  82.         }
  83.     }
  84.  
  85.     try
  86.     {
  87.         oCurFocus.focus()
  88.     }
  89.     catch(e)
  90.     {
  91.         //ignore error
  92.     }
  93. }
  94.  
  95.  
  96. // array that will contain all focusable objects on the page
  97. var aFocusableItemsArray = new Array()
  98.  
  99. function setArray()
  100.  /* This function makes an array of all the focusable objects on the page and
  101.  finds their exact locations on the page, making top and left properties for the center of each */
  102. {
  103.     // variable to track which focusable element we are dealing with
  104.     var nextElement = 0
  105.  
  106.     // for all objects on the page ...
  107.     for (i=0; i<body.all.length; i++)
  108.     {
  109.  
  110.         //variable to identify object
  111.         var obj = body.all(i)
  112.         // If object is focusable ...
  113.         if (obj.MCFocusable == "true")
  114.         {
  115.             // Set position, width, height, left and right as properties for the object
  116.             var objPosition = obj.getBoundingClientRect();
  117.             obj.nLeftPos = objPosition.left -2
  118.             obj.nRightPos = objPosition.right -2
  119.             obj.nTopPos = objPosition.top - 2
  120.             obj.nBottomPos = objPosition.bottom -2
  121.             obj.nWidth = (obj.nRightPos - obj.nLeftPos)
  122.             obj.nHeight = (obj.nBottomPos - obj.nTopPos)
  123.  
  124.             //find top coordinate for center of item: Y position on page plus half of height
  125.             var objCenterTop = (obj.nTopPos+(obj.nHeight/2))
  126.             //find left coordinate for center of item: X position on page plus half of width
  127.             var objCenterLeft = (obj.nLeftPos+(obj.nWidth/2))
  128.             // assign top and left as custom property of object
  129.             obj.nCenterYCoord = objCenterTop
  130.             obj.nCenterXCoord = objCenterLeft
  131.             // Place object in array of focusable items, in correct position
  132.             aFocusableItemsArray[nextElement] = obj
  133.             // update nextElement variable
  134.             nextElement++
  135.         }
  136.  
  137.         // check if object is a container for a "spinner"; if so, call function to show correct value
  138.         if (obj.MCSpinnerContainer == "true")
  139.         {
  140.             try
  141.             {
  142.                 initializeSpinner(obj)
  143.             }
  144.             catch(e)
  145.             {
  146.              // if above function call is not valid, ignore error
  147.              }
  148.         }
  149.     }
  150. }
  151.  
  152. function checkForOppositeArrow(direction)
  153. {
  154.  
  155.     /* this function checks if the arrow button pressed is in the opposite
  156.     direction from the last arrow button pressed (e.g. up, then down, or left, then right) */
  157.     // make sure that oPrevFocus and sPrevArrowDirection are not null
  158.     if (oPrevFocus == null || sPrevArrowDirection == null) return false
  159.     
  160.     switch(direction)
  161.     {
  162.         case "up":
  163.         {
  164.             if  (sPrevArrowDirection == "down")
  165.             {
  166.                 return true;
  167.             }
  168.             break;
  169.         }
  170.         case "down":
  171.         {
  172.             if  (sPrevArrowDirection == "up")
  173.             {
  174.                 return true;
  175.             }
  176.             break;
  177.         }
  178.         case "left":
  179.         {
  180.             if  (sPrevArrowDirection == "right")
  181.             {
  182.                 return true;
  183.             }
  184.             break;
  185.         }
  186.         case "right":
  187.         {
  188.             if  (sPrevArrowDirection == "left")
  189.             {
  190.                 return true;
  191.             }
  192.             break;
  193.         }
  194.     }
  195.     return false
  196. }
  197.  
  198. function changeFocus(direction)
  199. // this function moves the focus from one object to another based on input from the remote
  200. {
  201.     /* if the arrow button pressed is in the opposite
  202.     direction from the last arrow button pressed (e.g. up, then down, or left, then right)
  203.     move focus to the previous button, update variables, and end function */
  204.     if (checkForOppositeArrow(direction) == true)
  205.     {
  206.         // remember oCurFocus value before changing it
  207.         var oTemp = oCurFocus       
  208.         // set focus back to previous focus button
  209.         oCurFocus = oPrevFocus
  210.         oCurFocus.focus()       
  211.         // update oPrevFocus
  212.         oPrevFocus = oTemp
  213.         // update variable to track which direction arrow was pressed
  214.         sPrevArrowDirection = direction
  215.         // end function
  216.         return      
  217.     }
  218.     
  219.  
  220.     
  221.     // update variable to track where the focus was previous to current focus.
  222.     oPrevFocus = oCurFocus
  223.     // update variable to track which direction arrow was used to get between previous focus and current focus
  224.     sPrevArrowDirection = direction
  225.     
  226.     
  227.     // call function (below) to find nearest object to the one that has focus, in the direction of whatever arrow is pressed
  228.     var nearestObj = findClosestItem(direction)
  229.     
  230.     // if nearestObj is null, then make sPrevArrowDirectio null
  231.     if (nearestObj == null) sPrevArrowDirection = null
  232.  
  233.     // if focus is on the Shared Viewport and the user arrows in a direction that
  234.     // has no other focusable items, put focus back on viewport
  235.     if (oCurFocus.id == "SVP" && nearestObj == null)
  236.     {
  237.         window.external.MediaCenter.SharedViewPort.focus();
  238.         return
  239.     }
  240.     if (oCurFocus.id == "CVP" && nearestObj == null)
  241.     {
  242.         window.external.MediaCenter.CustomViewPort.focus();
  243.         return
  244.     }
  245.     // if there are no focusable objects in the direction indicated by arrow click, return
  246.     if (nearestObj == null)
  247.     {
  248.         return
  249.     }
  250.     // set focus on new object
  251.     oCurFocus = nearestObj
  252.     oCurFocus.focus()
  253.  
  254.     // If focus is on shared viewport placeholder, move focus to real shared viewport
  255.     if (oCurFocus.id == "SVP")
  256.     {
  257.         window.external.MediaCenter.SharedViewPort.focus();
  258.         return
  259.     }
  260.  
  261.     //If focus is on custom viewport placeholder, move focus to real custom viewport
  262.     if (oCurFocus.id == "CVP")
  263.     {
  264.         window.external.MediaCenter.CustomViewPort.focus();
  265.         return
  266.     }
  267.     try
  268.     {
  269.         // check if scrolling has taken place, using the didScroll function, and update positions of scrollable elements if needed
  270.         if (didScroll())
  271.         {
  272.             updateScrollPositions()
  273.         }
  274.     }
  275.     catch(e)
  276.     {
  277.         // if didScroll function is not present, ignore error
  278.     }
  279. }
  280.  
  281.  
  282. function findClosestItem(direction)
  283. {
  284. /* this function finds the the best item to navigate to based on which arrow key is pressed and on which item currently has the focus. To do this, it does up to three loops through all of the focusable items. On the first loop, it looks for items that are in a direct line in the direction selected, and finds the closest one. If the first loop finds no results, the second loop widens the search, looking for the closest item in the quadrant of the page (dividing the page like an X, not like a cross, with the current focus item at the center) in the direction selected. If there are no focusable items in the correct quadrant, the search widens a bit more, finding the closest item anywhere on the page (or, in effect, half of the page) in the direction selected. */
  285.     //Variable for object that currently has focus
  286.     var oOldObj = oCurFocus;
  287.     // variable to track shortest item distance. Start with a high number (10,000) for value
  288.     var nShortestItemDist = 10000
  289.     // variable to track which object is nearest to the one that currently has focus
  290.     var oNearestObj = null
  291.  
  292.     // first try to find any items that are exactly in the direction indicated; if any, return closest item
  293.     for (i=0; i < aFocusableItemsArray.length; i++)
  294.     {
  295.  
  296.         // Locate new object in array
  297.         oNewObj = aFocusableItemsArray[i]
  298.         // make sure object is not temporarily unfocusable
  299.         if (oNewObj.MCTempUnFocusable == "true") continue
  300.         // Make sure oNewObj is not oOldObj
  301.         if (oOldObj == oNewObj)
  302.         {
  303.             continue
  304.         }
  305.  
  306.         // call function to check if new object is in a straight line from old object, in direction indicated by selected arrow key;
  307.         // if so, set nTempDist variable for distance
  308.         var nTempDist = isInLine(oOldObj, oNewObj, direction)
  309.  
  310.         // if current object's distance is closest so far ...
  311.         if (nTempDist != null && nTempDist < nShortestItemDist)
  312.         {
  313.             // update variable for shortest distance so far
  314.             nShortestItemDist = nTempDist
  315.             // update variable for closest object so far
  316.             oNearestObj = oNewObj
  317.         }
  318.     }
  319.     // if above process finds any objects in a straight line from old object, return the closest one.
  320.     if (oNearestObj != null)
  321.     {
  322.         return oNearestObj
  323.     }
  324.  
  325.     ////////////////////////////
  326.     /* If no items exactly in correct direction, try to find any items that are in the correct quadrant
  327.     for the direction indicated; if any, return closest item */
  328.     for (i=0; i < aFocusableItemsArray.length; i++)
  329.     {
  330.         // Locate new object in array
  331.         oNewObj = aFocusableItemsArray[i]
  332.         // make sure object is not temporarily unfocusable
  333.         if (oNewObj.MCTempUnFocusable == "true") continue
  334.         // Make sure oNewObj is not oOldObj
  335.         if (oOldObj == oNewObj) continue
  336.  
  337.         // call function to check if new object is in the correct quadrant from old object, in direction indicated by selected arrow key;
  338.         // if so, set nTempDist variable for distance
  339.         var nTempDist = isInQuadrant(oOldObj, oNewObj, direction)
  340.  
  341.         // if current object's distance is closest so far (of items in this loop) ...
  342.         if (nTempDist != null && nTempDist < nShortestItemDist)
  343.         {
  344.             // update variable for shortest distance so far
  345.             nShortestItemDist = nTempDist
  346.             // update variable for closest object so far
  347.             oNearestObj = oNewObj
  348.         }
  349.     }
  350.     // if above process finds any objects in the correct quadrant from old object, return closest one
  351.     if (oNearestObj != null)
  352.     {
  353.         return oNearestObj
  354.     }
  355.  
  356.     /////////////////////////////////////
  357.     /* If no items are in correct quadrant, try to find any items that are in the correct half of the page
  358.     for the direction indicated; if any, return closest item */
  359.     for (i=0; i < aFocusableItemsArray.length; i++)
  360.     {
  361.         // Locate new object in array
  362.         oNewObj= aFocusableItemsArray[i]
  363.         // make sure object is not temporarily unfocusable
  364.         if (oNewObj.MCTempUnFocusable == "true") continue
  365.         // Make sure nNewObj is not oOldObj
  366.         if (oOldObj == oNewObj) continue
  367.  
  368.         // call function to check if new object is in the correct quadrant from old object, in direction indicated by selected arrow key;
  369.         // if so, set nTempDist variable for distance
  370.         var nTempDist = isInHalf(oOldObj, oNewObj, direction)
  371.  
  372.         // if current object's distance is closest so far (in this loop) ...
  373.         if (nTempDist != null && nTempDist < nShortestItemDist)
  374.         {
  375.             // update variable for shortest distance so far
  376.             nShortestItemDist = nTempDist
  377.             // update variable for closest object so far
  378.             oNearestObj = oNewObj
  379.         }
  380.     }
  381.  
  382.     // if above process finds any objects in the correct quadrant from old object, return closest object
  383.     if (oNearestObj != null)
  384.     {
  385.         return oNearestObj
  386.     }
  387.     // If not, return null
  388.     return null
  389. }
  390.  
  391.  
  392. function isInLine(oOldObj, oNewObj, direction)
  393. {
  394.     var nStraightDist = null
  395.     // make sure object is not temporarily unfocusable
  396.  
  397.     if (direction == "down")
  398.     {
  399.         // if old object is above (less in y coordinate) new object, return null
  400.         if (oOldObj.nCenterYCoord > oNewObj.nCenterYCoord)
  401.         {
  402.             return null
  403.         }
  404.         // if the current focus object's left edge is to the left of the new object's right edge, and the
  405.         // current focus object's right edge is to the right of the new object's left edge ...
  406.         if (oOldObj.nLeftPos < oNewObj.nRightPos && oNewObj.nLeftPos < oOldObj.nRightPos)
  407.         {
  408.             // then the new object and the old object overlap in the X coordinate
  409.             // calculate distance based on (top of oNewObj - bottom of oOldObj)
  410.             nStraightDist = (oNewObj.nTopPos - oOldObj.nBottomPos)
  411.         }
  412.         else
  413.         {
  414.             return null
  415.         }
  416.     }
  417.     if (direction == "up")
  418.     {
  419.         // if old object is below (greater in y coordinate) new object, return null
  420.         if (oOldObj.nCenterYCoord < oNewObj.nCenterYCoord)
  421.         {
  422.             return null
  423.         }
  424.         // if the current focus object's left edge is to the left of the new object's right edge, and the
  425.         // current focus object's right edge is to the right of the new object's left edge ...
  426.         if (oOldObj.nLeftPos < oNewObj.nRightPos && oNewObj.nLeftPos < oOldObj.nRightPos)
  427.         {
  428.             // then the new object and the old object overlap in the X coordinate
  429.             // calculate distance based on (top of oOldObj - bottom of oNewObj)
  430.             nStraightDist = (oOldObj.nTopPos - oNewObj.nBottomPos)
  431.         }
  432.         else
  433.         {
  434.             return null
  435.         }
  436.     }
  437.     if (direction == "left")
  438.     {
  439.         // if old object is left of (less in x coordinate) new object, return null
  440.         if (oOldObj.nCenterXCoord < oNewObj.nCenterXCoord)
  441.         {
  442.             return null
  443.         }
  444.         // if the current focus object's top edge is above of the new object's bottom edge,
  445.         // and the current focus object's bottom edge is below the new object's top edge ...
  446.         if (oOldObj.nTopPos < oNewObj.nBottomPos && oOldObj.nBottomPos > oNewObj.nTopPos)
  447.         {
  448.             // then the new object and the old object overlap in the Y coordinate
  449.             // calculate distance based on (left edge of oOldObj - Right edge of oNewObj)
  450.             nStraightDist = (oOldObj.nLeftPos - oNewObj.nRightPos)
  451.         }
  452.         else
  453.         {
  454.             return null
  455.         }
  456.     }
  457.     if (direction == "right")
  458.     {
  459.         // if old object is right of (greater in x coordinate) new object, return null
  460.         if (oOldObj.nCenterXCoord > oNewObj.nCenterXCoord)
  461.         {
  462.             return null
  463.         }
  464.         // if the current focus object's top edge is above of the new object's bottom edge,
  465.         // and the current focus object's bottom edge is below the new object's top edge ...
  466.         if (oOldObj.nTopPos < oNewObj.nBottomPos && oOldObj.nBottomPos > oNewObj.nTopPos)
  467.         {
  468.             // then the new object and the old object overlap in the Y coordinate
  469.             // calculate distance based on (left edge of oNewObj - Right edge of oOldObj )
  470.             nStraightDist = (oNewObj.nLeftPos - oOldObj.nRightPos)
  471.         }
  472.         else
  473.         {
  474.             return null
  475.         }
  476.     }
  477.     return nStraightDist
  478. }
  479.  
  480. function isInQuadrant(oOldObj, oNewObj, direction)
  481. {
  482.     // compare the difference between top and left for two objects to see what direction
  483.     // the new object is in relative to the object that currently has focus.
  484.     // Check distance between objects
  485.     var xDif = Math.abs(oOldObj.nCenterXCoord - oNewObj.nCenterXCoord);
  486.     var yDif = Math.abs(oOldObj.nCenterYCoord - oNewObj.nCenterYCoord);
  487.  
  488.     /* Determine quadrant (relative to the center of the current-focus object) that the new object falls in.
  489.     Note that the term "quadrant" is used loosely here; the dividing lines between the quadrants form
  490.     an X rather than a +. That way the arrow keys point to the center of each quadrant  */
  491.     var quadrant
  492.     if(xDif > yDif && oOldObj.nCenterXCoord > oNewObj.nCenterXCoord) quadrant = "left";
  493.     if(xDif > yDif && oOldObj.nCenterXCoord <= oNewObj.nCenterXCoord) quadrant = "right";
  494.     if(xDif <= yDif && oOldObj.nCenterYCoord > oNewObj.nCenterYCoord) quadrant = "up";
  495.     if(xDif <= yDif && oOldObj.nCenterYCoord <= oNewObj.nCenterYCoord) quadrant = "down";
  496.  
  497.     // make sure object is in correct quadrant ...
  498.     if (quadrant != direction) return null
  499.  
  500.     // Find distance between centers of objects; (project a right triangle and calculate hypotenuse)
  501.     var nQuadDist = Math.sqrt((xDif * xDif) + (yDif * yDif))
  502.     return nQuadDist
  503. }
  504.  
  505. function isInHalf(oOldObj, oNewObj, direction)
  506. /* if checkItemDist function cannot find any focusable items in the correct quadrant, this function
  507. widens the search a bit. Instead of using quadrants, it considers focusable items that lie at least 41 pixels away
  508. in the direction (up, down, left or right) indicated by the arrow key. Example: if the user hits the right arrow key,
  509. this function will consider any focusable item whose X coordinate is at least 41 pixels greater than that of the
  510. current-focus item, no matter what its Y coordiant is. From among those, it then calculates which is closest.        */
  511. {
  512.     // variable for distance between old and new objects
  513.     var nHalfDist
  514.  
  515.         var bIsInCorrectArea = false
  516.         // determine whether new item lies at least 41 pixels into the half of the page (relative to the current-focus item)
  517.         // that matches the arrow key pressed (example: if right arrowkey pressed, new item must
  518.         // have an X coodrinate that is at least 41 px greater than that of the current-focus item, or bIsInCorrectArea
  519.         // will not be set to true)
  520.         if (direction == "up" && (oOldObj.nCenterYCoord - 40) > oNewObj.nCenterYCoord)
  521.         {
  522.             bIsInCorrectArea = true
  523.         }
  524.         if (direction == "down" && (oOldObj.nCenterYCoord + 40) < oNewObj.nCenterYCoord)
  525.         {
  526.             bIsInCorrectArea = true
  527.         }
  528.         if (direction == "left" && (oOldObj.nCenterXCoord - 40) > oNewObj.nCenterXCoord)
  529.         {
  530.             bIsInCorrectArea = true
  531.         }
  532.         if (direction == "right" && (oOldObj.nCenterXCoord + 40) < oNewObj.nCenterXCoord)
  533.         {
  534.             bIsInCorrectArea = true
  535.         }
  536.  
  537.         // If object is not in correct area, end function
  538.         if (bIsInCorrectArea == false) return null
  539.  
  540.         // Compare the difference between top and left for two objects to see what direction
  541.         // the second object is in relative to the first.
  542.         // Check distance between objects
  543.         var xDif = Math.abs(oOldObj.nCenterXCoord - oNewObj.nCenterXCoord);
  544.         var yDif = Math.abs(oOldObj.nCenterYCoord - oNewObj.nCenterYCoord);
  545.  
  546.         // Find distance between centers of objects; (project a right triangle and calculate hypotenuse)
  547.         var nHalfDist = Math.sqrt((xDif * xDif) + (yDif * yDif))
  548.     return (nHalfDist)
  549. }
  550.  
  551.  
  552.  
  553.  
  554. function checkSVP()
  555. // this function makes the Shared Viewport focusable. To make it work, you must place a span (or div, or whatever)
  556. // in the lower left corner of the page to act as a placeholder for the actual Viewport; its ID must be "SVP"
  557. {
  558.     // make it so you can focus on the SVP placeholder span only if the real SVP is visible
  559.     try
  560.     {
  561.         if (window.external.MediaCenter.SharedViewPort.Visible == true)
  562.          {
  563.             /* MCTempUnFocusable is a custom property with which you can make an item temporarily non-focusable, without
  564.                 having to remove it from the aFocusableItemsArray. Set it to "false" */
  565.             SVP.MCTempUnFocusable="false"
  566.         }
  567.         else
  568.         {
  569.             // If the Shared Viewport is hidden, maks its stand-in non-focusable
  570.             SVP.MCTempUnFocusable="true"
  571.         }
  572.     }
  573.     catch(e)
  574.     {
  575.         // If above gets error, probably not using Media Center, so just make placeholder unfocusable
  576.         try
  577.         {
  578.             SVP.MCTempUnFocusable="true"
  579.         }
  580.         catch(e)
  581.         {
  582.             // if no object with id of "SVP" exists, ignore error
  583.         }
  584.     }
  585. }
  586.  
  587. function checkCVP()
  588. // If you are using a Custom Viewport this function makes it focusable.
  589. // To make it work, you must have a span (or div, or whatever) on your page to act as a placeholder.
  590. //Its ID must be "CVP" and it should be in the same position and size as your custom viewport
  591. {
  592.     // make it so you can focus on the CVP placeholder span only if the real CVP is visible
  593.     try
  594.     {
  595.         if (window.external.MediaCenter.CustomViewPort.Visible == true)
  596.          {
  597.             CVP.MCTempUnFocusable="false"
  598.         }
  599.         else
  600.         {
  601.             CVP.MCTempUnFocusable="true"
  602.         }
  603.     }
  604.     catch(e)
  605.     {
  606.         // If above gets error, probably not using Media Center, so just make placeholder unfocusable
  607.         try
  608.         {
  609.             CVP.MCTempUnFocusable="true"
  610.         }
  611.         catch(e)
  612.         {
  613.             // if no object with id of "CVP" exists, ignore error
  614.         }
  615.     }
  616. }